function addheaderstepinfo() {
    $(document).on('click','button[name=\"addheaderinfo\"]',function () {
        var twostep=$($(this).parent()).parent();
        var headerifno="<div>\n" +
            "                <div class=\"form-group\" style=\"display: inline-block\">\n" +
            "                    <label>key:</label>\n" +
            "                    <div style=\"display: inline-block;width: 200px\">\n" +
            "                        <input name='headkey' type=\"text\" class=\"form-control\">\n" +
            "                    </div>\n" +
            "                </div>\n" +
            "                <div class=\"form-group\" style=\"display: inline-block;width: 60%\">\n" +
            "                    <label>value:</label>\n" +
            "                    <div style=\"display: inline-block;width: 500px\">\n" +
            "                        <input name='headvalue' type=\"text\" class=\"form-control\">\n" +
            "                    </div>\n" +
            "                </div>\n" +
            "                <div style=\"display: inline-block\">\n" +
            "                    <button name=\"addheaderinfo\"><span class=\"glyphicon glyphicon-plus-sign\"></span></button>\n" +
            "                    <button name='removeheaderinfo'><span class=\"glyphicon glyphicon-minus-sign\"></span></button>\n" +
            "                </div>\n" +
            "            </div>";
        $(twostep).after(headerifno);
    });
}

function htmlinfotojson(){
    var resheadjson=$("#resheaderinfo").val();
    var newheadjson=JSON.stringify(JSON.parse(resheadjson), null, 2)
    $("#resheaderinfo").val(newheadjson);
}

function removeheaderinfo() {
    $(document).on('click','button[name=\"removeheaderinfo\"]',function () {
        var twostep=$($(this).parent()).parent();
        $(twostep).remove();
    });
}


function addcheckhtmlinfo(){
    $(document).on('click','button[name=\"addchecktableinfo\"]',function () {
        var twostep=$($(this).parent()).parent();
        var headerifno="<tr>\n" +
            "    <td>\n" +
            "        <input name=\"checkinfoname\" type=\"text\" class=\"form-control\">\n" +
            "    </td>\n" +
            "    <td>\n" +
            "    </td>\n" +
            "    <td>\n" +
            "        <input name=\"expectinfoname\" type=\"text\" class=\"form-control\">\n" +
            "    </td>\n" +
            "    <td>\n" +
            "        <button name=\"addchecktableinfo\"><span class=\"glyphicon glyphicon-plus-sign\"></span></button>\n" +
            "        <button name=\"removeheaderinfo\"><span class=\"glyphicon glyphicon-minus-sign\"></span></button>\n" +
            "    </td>\n" +
            "</tr>";
        $(twostep).after(headerifno);
        var checkmodelhtml=$("#checktypehtmlmode").html();
        $("#autocheckinfotables>tbody>tr:last-child>td:nth-child(2)").append(checkmodelhtml)

    });
}

function removecheckinfo() {
    $(document).on('click','button[name=\"removeheaderinfo\"]',function () {
        var twostep=$($(this).parent()).parent();
        $(twostep).remove();
    });
}

function addinterinfoparam(){
    var addhttpparam=getinterinfoparam();
    var interid=$("#interinfoid").html();
    var url="/api/interinfo/addinterinfo";
    if(interid > 1){
        url="/api/interinfo/upinterinfo";
    }
    $.ajax({
        type:"post",
        url:url,
        contentType: 'application/json',
        data:JSON.stringify(addhttpparam),
        success:function (data){
            getinterinfomodeltype(data)
        }
    })
}

function debuginterinfoweb(){
    var addhttpparam=getinterinfoparam();
    var url="/run/debuginter";
    $.ajax({
        type:"post",
        url:url,
        dataType:"html",
        contentType: 'application/json',
        data:JSON.stringify(addhttpparam),
        success:function (data){
            $("#debugmodel").modal('show');
            $("#debugmodelbody").html(data)
            htmlinfotojson();
        }
    })
}

function getinterinfoparam(){
    var posttype=1;
    if(typeof ($("#jsonhttptype:checked").val()) == "undefined"){
        posttype=2;
    }
    var checktype=1;
    if(typeof ($("#checkarrerttype:checked").val()) == "undefined"){
        checktype=2;
    }

    var addhttpparam={};
    addhttpparam["interid"]=$("#interinfoid").html();
    addhttpparam["interfacename"]=$("#interfacename").val();
    addhttpparam["intercasetype"]=1;
    addhttpparam["httptype"]=$("#httptypeselect").val();
    addhttpparam["httpmeth"]=$("#httpmethselect").val();
    addhttpparam["httpurl"]=$("#httpurlinput").val();
    addhttpparam["headstr"]=gethttpheaders();
    addhttpparam["postparamtype"]=posttype;
    addhttpparam["httpparam"]=$("#httpinfoparams").val();
    addhttpparam["checktype"]=checktype;
    addhttpparam["caseid"]=$("#smallcaseinfoid").html();
    addhttpparam["assinfoWebs"]=getchecktypelist();
    return addhttpparam;
}

function goaddinterinfohtml(caseid){
    window.location.href="/case/caseinfo?caseid="+caseid;
}

function gocaselisthtml(projectid){
    window.location.href="/case/list?projectid="+projectid;
}

function delinterinfomodel(delid){
    $("#delinteridmodel").html(delid);
    $("#delinterinfoModal").modal('show');
}

function delinterinfohttp(){
    $.post("/api/interinfo/delinterinfo",{
        interid:$("#delinteridmodel").html()
    },function (data){
        getinterinfomodeltype(data)
    })
}

function gethttpheaders(){
    var headobj={}
    $("#headerinfolists>div").each(function (){
        var headerkey=$($(this).find("[name=headkey]")).val();
        var headervalue=$($(this).find("[name=headvalue]")).val();
        if(headerkey.length>0){
            headobj[headerkey]=headervalue;
        }
    }
    )
    return headobj;
}

function getchecktypelist(){
    var array = [];
    $("#autocheckinfotables>tbody>tr").each(function (){
        var obj = {};
        var checkinfo=$($(this).find("[name=checkinfoname]")).val();
        var checktype=$($(this).find("[name=autoExpectEnumname]")).val();
        var expectinfo=$($(this).find("[name=expectinfoname]")).val();
        obj["checkinfo"]=checkinfo;
        obj["autotype"]=checktype;
        obj["expectinfo"]=expectinfo;
        array.push(obj);
        }
    )
    return array;
}


function refresh(){
    window.location.reload();
}


